package SingletonThread;

import com.mysql.cj.jdbc.MysqlDataSource;

import javax.sql.DataSource;

public class DBUtil {
    private static volatile DataSource dataSource;
    public static DataSource getDataSource() {
        if(dataSource == null) {
            synchronized (DBUtil.class) {
                if (dataSource == null) {
                    MysqlDataSource ds = new MysqlDataSource();
                    ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&useSSL=false");
                    ((MysqlDataSource)dataSource).setUser("root");
                    ((MysqlDataSource)dataSource).setPassword("123456");
                    dataSource = ds;
                }
            }
        }
        return dataSource;
    }
}
